package com.yc.sole.erp.biz;

import cn.hutool.core.bean.BeanUtil;
import com.yc.sole.erp.repository.StockLogRepository;
import com.yc.sole.erp.request.StockLogQueryReq;
import com.yc.sole.erp.response.StockLogResp;
import com.yc.sole.framework.mybatis.page.Paging;
import com.yc.sole.framework.mybatis.util.PageUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;

/**
 * 服务接口实现
 *
 * @author yizuomin
 * @date 2024-01-26
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class StockLogBiz {

    private final StockLogRepository stockLogRepository;

    /**
     * 通过id批量删除
     *
     * @param ids
     */
    @Transactional(rollbackFor = Exception.class)
    public void deleteStockLogByIds(Set<Long> ids) {
        // 删除入库记录
        stockLogRepository.deleteStockLogByIds(ids);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    public StockLogResp selectStockLogById(Long id) {
        return BeanUtil.copyProperties(stockLogRepository.selectStockLogById(id), StockLogResp.class);
    }

    /**
     * 分页查询
     *
     * @param page
     * @param queryReq
     * @return
     */
    public Paging<StockLogResp> selectStockLogPage(Paging<StockLogQueryReq> page, StockLogQueryReq queryReq) {
        return PageUtil.pageCopy(stockLogRepository.selectStockLogPage(page, queryReq), StockLogResp.class);
    }
}
